'use strict';
/**
 * @bussiness {商品}
 * @author {填写作者}
 * @date {创建时间}
 * **/
const Controller = require('egg').Controller;
class Goods extends Controller {
    /**@effect {拿取主页商品信息数据}**/
    async homeGoodsList() {
        const { ctx } = this;

        const res = await ctx.service.goods.index.homeGoods()
        res.sort((a, b) => {
            return b.goods_want - a.goods_want
        })
        console.log(res)
        ctx.body = {
            status: 200,
            data: res,
            msg: "success" // 截取前八个数据
        }
    }
    /**@effect {拿取所有商品信息数据}**/
    async allGoodsList() {
        const { ctx } = this;
        const params = ctx.request.body;
        const res = await ctx.service.goods.index.allGoods(params);
        // 每次请求随机打乱数据
        res.sort(() => {
            return Math.random() > .5 ? -1 : 1;
        });
        ctx.body = {
            status: 200,
            data: res,
            msg: "success"
        };
    };
    /**@effect {拿取搜索或者选择商品分类拿到信息数据}**/
    async takeCategoryGoods() {
        const { ctx } = this;
        const params = ctx.request.body;
        const res = await ctx.service.goods.index.takeGoodsList(params);
        res.sort(() => {
            return Math.random() > .5 ? -1 : 1;
        });
        ctx.body = {
            status:200,
            data: res,
            msg:"success"
        }
    }
    /**@effect {根据id拿到信息数据}**/
    async takeGoodsByIdx(){
        const {ctx} =this;
        const query = ctx.request.query;
        const res = await ctx.service.goods.index.takeGoodsById(query)
        ctx.body = {
            status:200,
            data:res,
            msg:"200"
        }
    }
}
module.exports = Goods 